﻿using System.Drawing;
using System.Windows.Forms;
using Tank90.Properties;

namespace Tank90
{
    public class PictureBoxEx : PictureBox
    {
        private readonly CustomMapPanel.ClickDlg _clickDlgPic;
        private MapElemenType _mapElementype;
        private Image typeImage;

        public PictureBoxEx(CustomMapPanel.ClickDlg clickDlg)
        {
            Width = 40;
            Height = 40;
            _clickDlgPic = clickDlg;
        }

        private void MapTypeSetImage(MapElemenType value)
        {
            switch (value)
            {
                case MapElemenType.FStone:
                    typeImage = Resources.fStone;
                    break;
                case MapElemenType.UStone:
                    typeImage = Resources.vUStone;
                    break;
                case MapElemenType.DStone:
                    typeImage = Resources.vDStone;
                    break;
                case MapElemenType.LStone:
                    typeImage = Resources.hLTStone;
                    break;
                case MapElemenType.RStone:
                    typeImage = Resources.hRTStone;
                    break;
                case MapElemenType.OStone:
                    typeImage = Resources.oStone;
                    break;


                case MapElemenType.FBrick:
                    typeImage = Resources.fBrick;
                    break;
                case MapElemenType.UBrick:
                    typeImage = Resources.vUBrick;
                    break;
                case MapElemenType.DBrick:
                    typeImage = Resources.vDBrick;
                    break;
                case MapElemenType.LBrick:
                    typeImage = Resources.hLBrick;
                    break;
                case MapElemenType.RBrick:
                    typeImage = Resources.hRBrick;
                    break;
                case MapElemenType.OBrick:
                    typeImage = Resources.oBrick;
                    break;

                case MapElemenType.Water:
                    typeImage = Resources.fWater;
                    break;
                case MapElemenType.Grass:
                    typeImage = Resources.fGrass;
                    break;
                case MapElemenType.White:
                    typeImage = Resources.fWhite;
                    break;
                default:
                    typeImage = Resources.Transparent;
                    break;
            }
        }


        public void SetProPrity(MapElemenType value, Point point)
        {
            Location = new Point(point.X - 20, point.Y - 20);
            MapTypeSetImage(value);
            if (typeImage != null)
            {
                Image = typeImage;
            }
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            var point = new Point(e.X + Location.X, e.Y + Location.Y);
            _clickDlgPic(point);
        }
    }
}